package tt.com.feesmanager.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import tt.com.common.enums.Status;
import tt.com.common.model.DeadProject;
import tt.com.common.util.CommonResult;
import tt.com.feesmanager.mapper.DeadprojectMapper;
import tt.com.feesmanager.service.feeConcessions;

import java.math.BigDecimal;

@Service
public class feeConcessionsImpl extends ServiceImpl<DeadprojectMapper, DeadProject> implements feeConcessions {
    @Override
    public CommonResult feeconcessions(DeadProject deadProject) {
        if (deadProject==null){
            return CommonResult.buildR(Status.DEFAULT,"不存在该服务项目，无法进行优惠");
        }else if (deadProject.getDiscountAmount()==null){
            return CommonResult.buildR(Status.DEFAULT,"该服务项目不存在优惠条件。");
        }else if (deadProject.getDiscountAmount()!=null){
            //费用乘上优惠价格 decimal类型的用multiply方法是乘运算
            BigDecimal multiply = deadProject.getCost().multiply(deadProject.getDiscountAmount());
            deadProject.setCost(multiply);
            return CommonResult.buildR(Status.OK,"优惠成功，优惠后价格为："+multiply);
        }else
            return CommonResult.buildR(Status.DEFAULT,"操作错误！");
    }
}
